var UserList = function () {

    var initPickers = function () {
        //init date pickers
        $('.date-picker').datepicker({
            rtl: Metronic.isRTL(),
            autoclose: true
        });
    }
    var refillgrid = function (obj){ // 重新填充数据  
    	
    }
    var handleOrders = function() {

        var grid = new Datatable();
            grid.init({
                src: $("#datatable_orders"),
                onSuccess: function(grid) {
                   console.log(grid);
                },
                onError: function(grid) {
                    // execute some code on network or other general error  
                },
                
                dataTable: {  // here you can define a typical datatable settings from http://datatables.net/usage/options 
                    "aLengthMenu": [
                        [20, 50, 100, 150, -1],
                        [20, 50, 100, 150, "All"] // change per page values here
                    ],
                    "aoColumns": [   {"mDataProp":"id","sClass": "center" },
                                     {"mDataProp":"picSmall","sClass": "center" },
                                     {"mDataProp":"nickname","sClass": "center"},
                                     {"mDataProp":"gender","sClass": "center"},
//                                     {"mDataProp":"address","sClass": "center"},
                                     {"mDataProp":"city","sClass": "center"},
                                     {"mDataProp":"phone","sClass": "center"},
                                     {"mDataProp":"createTime","sClass": "center"},
                                     {"mDataProp":"status","sClass": "center"},
                                     {"mDataProp":"status","sClass": "center"}
                                     ],
                                     
                     "aoColumnDefs": [
//                                      { "aTargets": [7], 
//                                    	   "bSearchable": false, 
//                                    	   "sType": 'date',
//                                    	   "fnRender": function ( oObj ) {
//                                    		  
//                                    		   var mDate = moment(oObj.aData.createTime);
//                                    	 
//                                    	              return  mDate.format("YYYY-MM-DD HH:mm");
//                                    	   }
//                                     },
								  	{ "aTargets": [0], 
                                	   "bVisible": false
                                     },
                                     
                                     
                                     { "aTargets": [1], 
                                  	   "bSearchable": false, 
                                  	   "mData": "头像",
                                  	   "fnRender": function ( oObj ) {
                            		  
                                  		 	console.log(oObj);
                                  		  	return  "<a href='/upload/"+oObj.aData.picSmall+"' class='fancybox-button' data-rel='fancybox-button'>"
                                        	+"<img class='img-responsive' src='/upload/"+oObj.aData.picSmall+"' alt=''>"
                                        	+"</a>";
                                     	}
                                     },
                                     
                                     { "aTargets": [6], 
                                  	   "bSearchable": false, 
                                  	   "sType": 'date',
                                  	   "fnRender": function ( oObj ) {
                                  		  
                                  		   var mDate = moment(oObj.aData.expireTime);
                                  	 
                                  	              return  mDate.format("YYYY-MM-DD HH:mm");
                                  	   }
                                     },
                                     { "aTargets": [3], 
                                    	   "bSearchable": false, 
                                    	   "sType": 'date',
                                    	   "fnRender": function ( oObj ) {
                                    		  
                                    		   if(oObj.aData.gender=="man"){
                                    			   return "男";
                                    		   }else if(oObj.aData.gender=="female"){
                                    			   return   "女";
                                    		   }else{
                                    			   return "其他";
                                    		   }
                                    	   }
                                       },
								
                                   
                                     { "aTargets": [7], 
                                    	   "bSearchable": false, 
                                    	   "mData": "详情",
                                           "mRender": function (data, type, full) {
                                          	 console.log(full);
                                          	 var btn = "<a class='btn default btn-xs green-stripe' href='admin/user/todetail/"+full.id+".htm'>详情</a>";
                                          	return  btn;
                                     	}
                                     },
                                     {
                                     "aTargets": [8],
                                     "mData": "操作",
                                     "mRender": function (data, type, full) {
                                    	 console.log(full);
                                    	 
                                    	 var btn = "<div class='margin-bottom-5'><a class='btn btn-default btn-sm' href='admin/user/toedit/"+full.id+".htm'><i class='fa fa-pencil'>编辑</i></a>";
											btn+="</div>";
                                    	return  btn;
                                    	 
                                    	 
                                       }
                                     },
                      ],
                    "iDisplayLength": 20, // default record count per page
                    "bServerSide": true, // server side processing
                    "sAjaxSource" : "admin/user/list.json?now=" + new Date().getTime(),
                    "fnServerData" : function(sSource, aDataSet, fnCallback) {  
                        $.ajax({  
                            "dataType" : 'json',  
                            "type" : "GET",  
                            "url" :sSource,  
                            "data" : aDataSet ,
                            "success" : fnCallback  
                        });  
                    },  
                    "aaSorting": [[ 1, "asc" ]] // set first column as a default sort by asc
                }
            });
        	$('.btn btn-sm yellow filter-submit margin-bottom').click(function () {
            	grid.fnDraw();
        	});
            // handle group actionsubmit button click
            grid.getTableWrapper().on('click', '.table-group-action-submit', function(e){
                e.preventDefault();
                var action = $(".table-group-action-input", grid.getTableWrapper());
                if (action.val() != "" && grid.getSelectedRowsCount() > 0) {
                    grid.addAjaxParam("sAction", "group_action");
                    grid.addAjaxParam("sGroupActionName", action.val());
                    var records = grid.getSelectedRows();
                    for (var i in records) {
                        grid.addAjaxParam(records[i]["name"], records[i]["value"]);    
                    }
                    grid.getDataTable().fnDraw();
                    grid.clearAjaxParams();
                } else if (action.val() == "") {
                    Metronic.alert({type: 'danger', icon: 'warning', message: 'Please select an action', container: grid.getTableWrapper(), place: 'prepend'});
                } else if (grid.getSelectedRowsCount() === 0) {
                    Metronic.alert({type: 'danger', icon: 'warning', message: 'No record selected', container: grid.getTableWrapper(), place: 'prepend'});
                }
            });

    }

    return {

        //main function to initiate the module
        init: function () {
            initPickers();
            handleOrders();
        }
    	

    };

}();

var test ={
		
};





